import java.util.*;

/**
 * @author gao
 * @date 2025/9/20 12:36
 */

public class Solution {
    public boolean wordBreak(String s, List<String> wordDict) {
        int n = s.length();
        boolean[] dp = new boolean[n + 1];
        dp[0] = true;
        // 将字符串s前面加上一个逗号，方便处理
        s = "," + s;

        // dp[i]表示s[1,i]是否可以被空格拆分成一个或多个在字典中出现的单词
        Set<String> set = new HashSet<>(wordDict);

        for (int i = 1; i <= n; i++) {
            for (int j = i; j >= 1; j--) {
                if (dp[j - 1] && set.contains(s.substring(j, i + 1))) {
                    // 如果s[1,j-1]可以被拆分，并且s[j,i]在字典中，则s[1,i]可以被拆分
                    dp[i] = true;
                    break;
                }
            }
        }
        return dp[n];
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            String s = in.nextLine();
            int n = in.nextInt();
            in.nextLine();
            List<String> wordDict = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                wordDict.add(in.nextLine());
            }
            Solution solution = new Solution();
            System.out.println(solution.wordBreak(s, wordDict));
        }
    }
}